<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%><%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"
%><%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"
%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><f:bundle basename="message">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Operation Desktop</title>
		<script src="https://www.google.com/jsapi?key=ABQIAAAAZeErT9rEVT9d5p7HJy_1zRSNxWYpA3ox9AppeOcWcMeCr0DgohQKd0vEK59Q_i4y41Se_gdbjc3KUw" type="text/javascript"></script>
		<script type="text/javascript">//<![CDATA[
			function setCookie(c_name, value, exdays) {
				var exdate = new Date();
				exdate.setDate(exdate.getDate() + exdays);
				var c_value = escape(value)
						+ ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
				document.cookie = c_name + "=" + c_value;
			}
		
			function getCookie(c_name) {
				var i,x,y,ARRcookies=document.cookie.split(";");
				for (i=0;i<ARRcookies.length;i++) {
					x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
					y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
					x=x.replace(/^\s+|\s+$/g,"");
					if (x==c_name) {
						return unescape(y);
					}
				}
			}
			
			function getContext() {
				
				var context;
				var endOfContext = location.pathname.indexOf("/", 1);
				if (endOfContext == -1) {
					context = location.pathname;
				} else {
					context = location.pathname.substring(0, endOfContext);
				}
		
				return context;
			}
		//]]></script>
		<script type="text/javascript">//<![CDATA[
			google.load("jquery", "1.5.0");
			
			// This function will be called by Pivot
			function echo(text) {
				//alert(helloText);
				$("#log-container").append("<p>" + text + "</p>");
			}
			
			// This function will call into Pivot
			function onHelloButtonClick() {
				var bf2rconApplet = document.getElementById("bf2rconApplet");
				bf2rconApplet.getApplication().echo("Hello from JavaScript!");
			}
		//]]></script>
	</head>
	<body>
		<div id="log-container">
			<p><f:message key="loading"/></p>
		</div>
		<div id="applet-container">
			<script type="text/javascript" src="<c:url value="/deployJava.js"/>"></script>
			<script type="text/javascript">
				var attributes = {
					id : "bf2rconApplet",
					width : "0",
					height : "0"
				};
				var parameters = {
					jnlp_href : "<c:url value="/webstart/launch.jnlp"/>",
					startup_properties : [location.search.substring(1), "context=" + getContext(), "session=" + getCookie("JSESSIONID")].join("&")
				};
					<%--
					application_class_name : "org.zbclan.bf2.rcon.BF2RconApp",
					system_properties : "",
					boxbgcolor: "cyan",
					boxborder: "false",
					centerimage: "true",
					image: "<c:url value="/loading-3.gif"/>"
					/* TODO loading and java detection prompt */
					--%>
				var version = "1.6";
				deployJava.runApplet(attributes, parameters, version);
			</script>
			<%--
			<button onclick="onHelloButtonClick()">Say Hello</button>
			 --%>
		</div>
	</body>
</f:bundle></html>